package wsi.exp.exp5;

import java.util.LinkedList;
import java.util.List;

import org.rygh.core.xml.XmlLeaf;

import wsi.function.Function;

public class JudgeTuple {

	public static Boolean __DEBUG = false;

	private final String knowledgeDb;
	private final Function function;
	private final List<JudgeGroup> pairGroup = new LinkedList<>();

	public JudgeTuple(String knowledgeDb, Function function) {
		this.knowledgeDb = knowledgeDb;
		this.function = function;
	}

	public void addConditionPairs(boolean def, String suffix,
			List<String> strings) {
		JudgeGroup pairs = new JudgeGroup(def, suffix);

		for (int i = 0; i < strings.size(); i += 2)
			pairs.add(strings.get(i), strings.get(i + 1));

		pairGroup.add(pairs);
	}

	public Function getFunction() {
		return function;
	}

	public String getKnowledgeDb() {
		return knowledgeDb;
	}

	/**
	 * 
	 * @return the default value of the group which can judge, otherwise null
	 *         indicating cannot judge.
	 */
	public Boolean judge(XmlLeaf node) {
		for (JudgeGroup p : pairGroup) {
			Boolean j = p.judge(node);

			if (j != null)
				return j;
			else {
				if (__DEBUG)
					System.out.printf("[info] group cannot judge %s\n", p);
			}
		}

		return null;
	}

}
